package com.monika.main.system.util.doc;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.converter.PicturesManager;
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.PictureType;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author:whh
 * @date: 2025-05-10 14:38
 * <p></p>
 */
public class DOCX extends Document<XWPFDocument,byte[]> {


    /**
     * 总段落数
     */
    private int paragraphs;


    /**
     * 当前页
     */
    private int cur = 1;

    /**
     * 总页数
     */
    private final int pages;

    /**
     * 每页段落数
     */
    private int pageGraphs=10;


    public DOCX(File docx,int pageGraphs) throws IOException {
        super(new XWPFDocument(new FileInputStream(docx)));
        paragraphs=pageGraphs;
        paragraphs=doc.getParagraphs().size();
        pages= paragraphs % pageGraphs == 0 ? (paragraphs/pageGraphs): (paragraphs/pageGraphs+1);
    }


    public boolean hasNext() {
        return cur<=pages;
    }

    public byte[] next() {
        List<XWPFParagraph> page = page();

        for (XWPFParagraph xp : page) {
        }
        XWPFDocument document=new XWPFDocument();
        for (int i = 0; i < page.size(); i++) {
            document.setParagraph(page.get(i),i);
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();




        return new byte[0];
    }



    private List<XWPFParagraph>page(){
        int skip=(cur-1)*pageGraphs;
        List<XWPFParagraph> list = doc.getParagraphs();
        cur++;
        return list.stream().skip(skip).limit(pageGraphs).collect(Collectors.toList());

    }

    public static void main(String[] args) {

    }
}
